﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechCraftEngine;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;


namespace Blox.States
{
    class MenuState : State
    {
#if XBOX
        private const string STARTTEXT = "Menu";
#else
        private const string STARTTEXT = "Menu";
#endif

        private SpriteBatch _spriteBatch;
        private SpriteFont _spriteFont;
        private Vector2 _startTextPosition;       
        //public TitleState(TechCraftGame game)
        //    : base(game)
        //{
        //}

        public MenuState()
        {
        }

        public override void Initialize()
        {
            _spriteBatch = new SpriteBatch(Game.GraphicsDevice);
        }

        public override void LoadContent()
        {
            _spriteFont = Game.Content.Load<SpriteFont>("Fonts\\console");
            Vector2 textSize = _spriteFont.MeasureString(STARTTEXT);
            _startTextPosition = new Vector2((Game.GraphicsDevice.Viewport.Width / 2.0f) - (textSize.X / 2), 20);
        }
        
        public override void Update(GameTime gameTime)
        {
        }

        PlayerIndex _controllerIndex;
        public override void ProcessInput(GameTime gameTime)
        {
            if (_game.InputState.IsKeyPressed(Keys.Escape, null, out _controllerIndex) ||
                _game.InputState.IsButtonPressed(Buttons.Back, null, out _controllerIndex))
            {
                Game.IsMouseVisible = false;
                Game.StateManager.ActiveState = Game.StateManager.GetState(typeof(PlayingState));
            }
        }

        /*public void StorageDeviceSelected(IAsyncResult result)
        {
            _game.StorageDevice = StorageDevice.EndShowSelector(result); 

            //_game.StorageDevice = Guide.EndShowStorageDeviceSelector(result);
        }*/


        //private Manager manager;

        public override void Draw(GameTime gameTime)
        {
            Game.GraphicsDevice.Clear(Color.Black);

            /*manager = new Manager(Game.GetBase(), Game.Graphics, "Default");
            manager.Skin = new Skin(manager, "Default");
            

            Game.IsMouseVisible = true;

            manager.Initialize();

            Button b = new Button(manager);
            b.Name = "ExitButton";
            b.Text = "Exit game";
            b.Click += new TomShane.Neoforce.Controls.EventHandler(b_Click);
            b.SetPosition(int.Parse(((Game.GraphicsDevice.Viewport.Width / 2.0f) - (200 / 2)) + ""), Game.GraphicsDevice.Viewport.Height - 100);
            b.SetSize(200, 50);*/

            _spriteBatch.Begin();
            _spriteBatch.DrawString(_spriteFont, STARTTEXT, _startTextPosition, Color.White);
            _spriteBatch.End();
        }

        /*void b_Click(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            Game.Exit();
        }*/


    }
}
